import typescript from "rollup-plugin-typescript2";
import vue from "rollup-plugin-vue";
import terser from "@rollup/plugin-terser";
import copy from "rollup-plugin-copy";
import del from "rollup-plugin-delete";
import resolve from "@rollup/plugin-node-resolve";
import postcss from "rollup-plugin-postcss";

export default [
  {
    // 打包组件的任务
    input: "packages/components/index.ts", // 打包入口
    // 打包的输出
    output: {
      dir: "dist",
      format: "esm",
    },
    // 外部依赖，这一部分依赖不需要进行打包
    external: ["vue"],
    // 指定要使用的插件，注意插件是有顺序
    plugins: [
      del({ targets: "dist" }), // 先把上一次的打包内容删除掉
      vue({
        include: ["**/*.vue"],
      }),
      postcss({
        minimize: true,
        extract: false,
      }),
      resolve({
        extensions: [".ts", ".vue", ".js"], // 添加扩展名解析
      }),
      typescript({
        tsconfig: "tsconfig.app.json",
        allowNonTsExtensions: true,
        useTsconfigDeclarationDir: true, // 关键配置
        tsconfigOverride: {
          compilerOptions: {
            declarationDir: "./dist",
          },
        },
      }),
      terser(),
      copy({
        targets: [
          { src: "packages/components/package.json", dest: "dist" },
          { src: "README.md", dest: "dist" },
        ],
      }),
    ],
  },
];
